﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNA_TD.Shells;

namespace XNA_TD
{
    public class AARTower : Tower
    {
        static ModelBone[] gunBones = null;
        static Random random;
        static LvlInfo startInfo;

        static Matrix[] boneTransforms;
        int gunIndex = 0;

        public AARTower(Vector3 pos)
            : base(pos, "Tower/AARTower")
        {
            if (gunBones == null)
            {
                gunBones = new ModelBone[7];
                gunBones[0] = model.Bones["AARTowerGun1"];
                gunBones[1] = model.Bones["AARTowerGun2"];
                gunBones[2] = model.Bones["AARTowerGun3"];
                gunBones[3] = model.Bones["AARTowerGun4"];
                gunBones[4] = model.Bones["AARTowerGun5"];
                gunBones[5] = model.Bones["AARTowerGun6"];
                gunBones[6] = model.Bones["AARTowerGun7"];

                boneTransforms = new Matrix[model.Bones.Count];
                random = new Random();
                startInfo = new LvlInfo("", 40, 7, 5, 200, 500, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser);

                startInfo
                    .Add("Damage Upgrade", 60, 7, 5, 200, 250, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser)
                    .Add("Damage Upgrade", 100, 7, 5, 200, 400, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser);

                startInfo
                    .Add("Range Upgrade", 40, 10, 5, 200, 250, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser)
                    .Add("Range Upgrade", 40, 15, 5, 200, 500, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser);

                startInfo
                    .Add("Speed Upgrade", 40, 7, 8, 200, 250, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser)
                    .Add("Speed Upgrade", 40, 7, 15, 200, 500, GegnerTyp.Boden | GegnerTyp.Luft | GegnerTyp.Wasser);
            }

            lvlInfo = startInfo;

            ResetHealth();
        }

        protected override Matrix[] CalculateAbsoluteBoneTransforms()
        {
            model.Root.Transform = root * Matrix.CreateTranslation(position);
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            return boneTransforms;
        }

        protected override void Shot()
        {
            gunIndex = random.Next(gunBones.Length);
            CalculateAbsoluteBoneTransforms();

            Vector3 translation = boneTransforms[gunBones[gunIndex].Index].Translation;
            Register(new Rocket(translation, lvlInfo.attackDmg, target));
        }
    }
}
